﻿/*
Commerce by Onex – eCommerce software platform (www.ecommerce.byonex.com)
Copyright (C) 2008-2010 by Onex Group

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ShopBLL;
using ShopModel;

public partial class PrintProduct : BasePage
{
    #region CONSTANTS

    private const int COLUMN = 6;

    #endregion CONSTANTS

    #region VARIABLES

    public Products product;

    #endregion VARIABLES

    #region METHODS

    private void GeneratePropertyPanel(List<ProductProperty> Properties)
    {
        List<ProductProperty> result = new List<ProductProperty>();
        bool newRow = true;
        Dictionary<int, ProductProperty> multiPropertyCells = new Dictionary<int, ProductProperty>();
        ProductProperty proper;

        foreach (ProductProperty current in Properties)
        {

            if (current.TypeOfProperty == PropertyType.MultiDictionary && multiPropertyCells.ContainsKey(current.Id))
            {
                proper = multiPropertyCells[current.Id];
                newRow = false;
            }
            else
            {
                proper = new ProductProperty();
                newRow = true;
                proper.Name = current.Name;
                proper.Id = current.Id;
                if (current.TypeOfProperty == PropertyType.MultiDictionary)
                {
                    multiPropertyCells.Add(current.Id, proper);
                }
            }

            if (current.TypeOfProperty == PropertyType.Numeric)
            {
                proper.Value = current.NumericValue.ToString();
            }
            else if (current.TypeOfProperty == PropertyType.MultiDictionary && !newRow)
            {
                proper.Value += "<br /> " + current.Value;
            }
            else
            {
                proper.Value = current.Value;
            }

            if (newRow)
            {
                result.Add(proper);
            }
        }

        rptProperty.DataSource = result;
        rptProperty.DataBind();
    }

    #endregion METHODS

    #region PAGE EVENTS

    protected void Page_Load(object sender, EventArgs e)
    {
        int productId = Convert.ToInt32(Request.QueryString["Id"]);

        product = ProductsManager.Instance.GetProduct(productId, ShopBLL.CommonTools.CurrentLanguageID);

        GeneratePropertyPanel(product.PropertyList);
        if (product != null)
        {
            if (product.Pictures.Count > 0)
            {
                foreach (PictureInfo p in product.Pictures)
                {
                    if (p.IsMain)
                    {
                        imgProduct.ImageUrl = p.VirtualPath;
                    }
                }
            }
            else
            {
                imgProduct.Visible = false;
            }
        }
    }

    #endregion PAGE EVENTS
}
